package com.ruoyi.function.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.function.domain.bo.TechnicianBo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.function.domain.Technician;
import com.ruoyi.function.service.ITechnicianService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 技师Controller
 * 
 * @author ruoyi
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/function/technician")
public class TechnicianController extends BaseController
{
    @Autowired
    private ITechnicianService technicianService;

    /**
     * 查询技师列表
     */
//    @PreAuthorize("@ss.hasPermi('function:technician:list')")
    @GetMapping("/list")
    public TableDataInfo list(Technician technician)
    {
        startPage();
        List<Technician> list = technicianService.selectTechnicianList(technician);
        return getDataTable(list);
    }

    /**
     * 导出技师列表
     */
//    @PreAuthorize("@ss.hasPermi('function:technician:export')")
    @Log(title = "技师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Technician technician)
    {
        List<Technician> list = technicianService.selectTechnicianList(technician);
        ExcelUtil<Technician> util = new ExcelUtil<Technician>(Technician.class);
        util.exportExcel(response, list, "技师数据");
    }

    /**
     * 获取技师详细信息
     */
//    @PreAuthorize("@ss.hasPermi('function:technician:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(technicianService.selectTechnicianById(id));
    }

    /**
     * 新增技师
     */
//    @PreAuthorize("@ss.hasPermi('function:technician:add')")
    @Log(title = "技师", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TechnicianBo technicianBo)
    {
        return toAjax(technicianService.insertTechnician(technicianBo));
    }

    /**
     * 小程序注册技师
     */
    @Log(title = "技师", businessType = BusinessType.INSERT)
    @PostMapping("/register")
    public AjaxResult register(@RequestBody TechnicianBo technicianBo)
    {
        return toAjax(technicianService.register(technicianBo));
    }
    /**
     * 修改技师
     */
    @Log(title = "技师", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TechnicianBo technicianBo)
    {
        int i = technicianService.updateTechnician(technicianBo);
      return   AjaxResult.success();
    }

    /**
     * 删除技师
     */
    @PreAuthorize("@ss.hasPermi('function:technician:remove')")
    @Log(title = "技师", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(technicianService.deleteTechnicianByIds(ids));
    }

    /**
     * 审核资质
     */
    @Log(title = "技师", businessType = BusinessType.UPDATE)
    @PutMapping("/check")
    public AjaxResult check(@RequestBody Technician technician)
    {
        return toAjax(technicianService.check(technician));
    }


    @PutMapping("/receivingOrder/{receivingOrder}")
    public AjaxResult receivingOrder(@PathVariable Integer receivingOrder) {

        return toAjax(technicianService.receivingOrder(receivingOrder));
    }
}
